package com.example.multitenant.multitenant.config

import com.example.multitenant.base.Log

/**
 * @author xiang
 * @Date 2022/8/23 11:50
 **/
object TenantContext {

    private const val TAG = "TenantContext"

    private val currentTenant = InheritableThreadLocal<String>()

    fun setTenantId(tenantId: String) {
        Log.i(TAG, "Setting tenantId to $tenantId")
        currentTenant.set(tenantId)
    }

    fun getTenantId(): String {
        return currentTenant.get() ?: ""
    }

    fun clear() {
        currentTenant.remove()
    }
}